/*
 * Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package top.continew.admin.hanfu.core.oss;

import cn.hutool.core.io.FileUtil;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;
import top.continew.admin.hanfu.domain.OssFile;

import java.io.File;

@Component
public class OssFactory {

    public OssFile createOssFile() {
        return new OssFile();
    }

    public OssFile createOssFile(String subject, Integer user, MultipartFile file, String serverPath) {
        OssFile ossFile = new OssFile();

        ossFile.setSubject(subject);
        ossFile.setUserId(user);
        ossFile.setOriginFileName(file.getOriginalFilename());
        ossFile.setFileSize((int)file.getSize());
        ossFile.setServerPath(serverPath);
        ossFile.setUpdataBy(user + "");
        ossFile.setUpdataTime(System.currentTimeMillis() + "");
        ossFile.setStatus(1 + "");
        ossFile.setFileType(FileUtil.getType(new File(serverPath)));
        return ossFile;
    }

    public OssFile createOssFile(String subject, Integer user, File file, String serverPath) {
        OssFile ossFile = new OssFile();

        ossFile.setSubject(subject);
        ossFile.setUserId(user);
        ossFile.setOriginFileName(file.getName());
        ossFile.setFileSize((int)file.length());
        ossFile.setServerPath(serverPath);
        ossFile.setUpdataBy(user + "");
        ossFile.setUpdataTime(System.currentTimeMillis() + "");
        ossFile.setStatus(1 + "");
        ossFile.setFileType(FileUtil.getType(file));
        return ossFile;
    }

}
